import Cookies from 'js-cookie';
import Member from '@/common/model/Member'

const user = {
    state: {
        info: new Member()
    },
    mutations: {
        login(status, obj) {
            Cookies.set('user', obj.username);
            Cookies.set('password', obj.password);
            Cookies.set('access', obj.access);
            localStorage.token = obj.token;
        },
        logout (state, vm) {
            Cookies.remove('user');
            Cookies.remove('password');
            Cookies.remove('access');
            //localStorage.clear();
        },
        setUserInfo (state, info) {
            if(info instanceof Object) {
                state.info = Object.assign({}, state.info, info);
            }else {
                state.info = Object.assign({}, state.info, {});
            }
        }
    }
};

export default user;
